libxl: Make 'xl vcpu-set' work properly on overcommited hosts with an override.
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Mon, 13 May 2013 19:29:14 +0000 (15:29 -0400)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 14 May 2013 09:02:13 +0000 (10:02 +0100)
commitafab6f6788b3e1eeed7fd7d2550bca96edca2720
treeb7f3af105652a0677ae8bc12171aec7cfa167194
parent6a0a079a934bb45c070aa86861453a3fdbaa0b85
libxl: Make 'xl vcpu-set' work properly on overcommited hosts with an override.

The libxl_cpu_bitmap_alloc(..) function, if provided with a zero
value for max CPUs will call xc_get_max_cpus() which will retrieve
the number of physical CPUs the host has. This is usually
OK if the guest's maxvcpus <= host pcpus. But if the value
is different, then the bitmap for VCPUs is limited by the
number of CPUs the host has.

This is incorrect as what we want is to hotplug in the guest
the amount of CPUs that the user specified on the command line
and not be limited by the amount of physical CPUs.

This means that a guest config like this:

vcpus=8
maxvcpus=32

and on a 4 PCPU machine doing

xl vcpu-set <guest name> 16

won't work. This is b/c the the size of the bitmap is one byte
so it can only hold up to 8 VCPUs. Hence anything above that
is going to be ignored.

Note that this patch also fixes the bitmap setting - as it
would set all of the bits allowed. Meaning if the user had a 4PCPU
host we would still allow the user to set 8VCPUs. This second
iteration of the patch fixes this.

Note that all of the libxl_cpu_bitmap_[test|set] silently ignore
any test or sets above its size:

     if (bit >= bitmap->size * 8)
         return 0;

so we were never notified off this bug.

This patch warns the user if they are trying to do this. If the
user really wants to do this they have to provide the --ignore-host
parameter to bypass this check.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
tools/libxl/xl_cmdimpl.c
tools/libxl/xl_cmdtable.c